from appui import *
from interface import *
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys

class AppWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.ui.pushButton.clicked.connect(self.goto_interface)
        self.show()

    def goto_interface(self):
        account = self.ui.lineEdit.text()
        passward = self.ui.lineEdit_2.text()
        if account == "xufuyong" and passward == "1234567890":
            InterfaceWindow()
            self.close()
        else:
            pass

    # 移动窗口
    def mousePressEvent(self, event):
        if (event.button() == QtCore.Qt.LeftButton) and (self.isMaximized() == False):
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标窗口位置
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标

    def mouseMoveEvent(self, mouse_event):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(mouse_event.globalPos() - self.m_Position)  # 更改窗口位置
            mouse_event.accept()

    def mouseReleaseEvent(self, mouse_event):
        self.m_flag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

class InterfaceWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow_app()
        self.ui.setupUi(self)
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.ui.pushButton_4.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(0))
        self.ui.pushButton_5.clicked.connect(lambda: self.ui.stackedWidget.setCurrentIndex(1))
        self.ui.pushButton_2.clicked.connect(self.resize_win)
        self.show()

    def resize_win(self):
        if self.isMaximized():
            self.showNormal()
            # self.ui.pushButton_2.setIcon(QtGui.QIcon(":/icons/fd.png"))
        else:
            self.showMaximized()
            # self.ui.pushButton_2.setIcon(QtGui.QIcon(":/icons/fd.png"))

    # 移动窗口
    def mousePressEvent(self, event):
        if (event.button() == QtCore.Qt.LeftButton) and (self.isMaximized() == False):
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标窗口位置
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标

    def mouseMoveEvent(self, mouse_event):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(mouse_event.globalPos() - self.m_Position)  # 更改窗口位置
            mouse_event.accept()

    def mouseReleaseEvent(self, mouse_event):
        self.m_flag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = AppWindow()
    sys.exit(app.exec_())